package fragments;


import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.baseproject.BaseFragment;
import com.example.administrator.newxlmedical.R;

import beans.NewUserInfoBean;
import beans.RegisterInfoBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import constants.Constants;
import constants.HandlerConstant;
import customhandler.MyHandler;
import singleton.SingletonClass;
import utils.ObjectSaveUtil;

/**
 * A simple {@link Fragment} subclass.
 */
public class RegisterRoleFragment extends BaseFragment {

    @BindView(R.id.tv_register_role_manage)
    TextView tvManage;
    @BindView(R.id.tv_register_role_head_nurse)
    TextView tvHeadNurse;
    @BindView(R.id.tv_register_role_nurse)
    TextView tvNurse;
    @BindView(R.id.tv_register_role_supplier)
    TextView tvSupplier;
    @BindView(R.id.tv_register_role_me)
    TextView tvMe;
    Unbinder unbinder;
    @BindView(R.id.ll_register_role_me)
    LinearLayout llRegisterRoleMe;

    private MyHandler allHandler;
    private NewUserInfoBean.DataBean userInfoBean;

    public RegisterRoleFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_register_role, container, false);
        unbinder = ButterKnife.bind(this, view);
        userInfoBean = (NewUserInfoBean.DataBean) ObjectSaveUtil.readObject(mContext, Constants.USER_INFO_BEAN, Constants.USER_INFO_BEAN);
        if (userInfoBean.getRoleInfoId() != 5) {
            llRegisterRoleMe.setVisibility(View.GONE);
        }else {
            llRegisterRoleMe.setVisibility(View.VISIBLE);
        }
        return view;
    }

    @Override
    protected void initView() {
        super.initView();
        allHandler = SingletonClass.getSingleton(MyHandler.class);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.tv_register_role_manage, R.id.tv_register_role_head_nurse, R.id.tv_register_role_nurse, R.id.tv_register_role_supplier, R.id.tv_register_role_me})
    public void onViewClicked(View view) {
        Message message = allHandler.obtainMessage();
        RegisterInfoBean bean = new RegisterInfoBean();
        message.obj = bean;
        message.what = HandlerConstant.REGISTER_ROLE;
        switch (view.getId()) {
            case R.id.tv_register_role_manage:
                bean.setRegisterRole(Constants.ROLE_MANAGE);
                break;
            case R.id.tv_register_role_head_nurse:
                bean.setRegisterRole(Constants.ROLE_HEAD_NURSE);
                break;
            case R.id.tv_register_role_nurse:
                bean.setRegisterRole(Constants.ROLE_NURSE);
                break;
            case R.id.tv_register_role_supplier:
                bean.setRegisterRole(Constants.ROLE_SUPPLIER);
                break;
            case R.id.tv_register_role_me:
                bean.setRegisterRole(Constants.ROLE_FACTORY);
        }
        allHandler.sendMessage(message);
    }
}
